package org.liuyuantao.lucene.analyzer;

import org.apache.lucene.analysis.Analyzer;

import org.apache.lucene.analysis.Tokenizer;
import org.apache.lucene.analysis.core.LowerCaseFilter;
import org.apache.lucene.analysis.core.StopAnalyzer;
import org.apache.lucene.analysis.core.StopFilter;
import org.apache.lucene.analysis.util.CharArraySet;
import org.liuyuantao.lucene.utils.IKTokenizer5x;

public class MySameAnalyzer extends Analyzer {
    private SamewordContext samewordContext;

    public MySameAnalyzer(SamewordContext swc) {
        samewordContext = swc;
    }

    @Override
    protected TokenStreamComponents createComponents(String fieldName) {
        Tokenizer tokenizer = new IKTokenizer5x(true);
        return new TokenStreamComponents(tokenizer, new MySameTokenFilter(new StopFilter(new LowerCaseFilter(tokenizer),
                new CharArraySet(StopAnalyzer.ENGLISH_STOP_WORDS_SET, true)), this.samewordContext));
    }
}
